<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>功能室审批详情-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background-color: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left">
	  			<a href="<%=basePath %>/ls/function/room?from=sys" class="icon icon-109 f-white">返回</a > 
	  		</div>
	    	<h1 class="weui-header-title">功能室申请详情</h1>
	    </div>
		<div class="weui_tab_bd">
			<div class="weui_cells mt0">
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">申请人</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>${detail.applyer }</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">所在部门</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>${detail.depart }</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">申请场室</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>${detail.roomName }</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">使用日期</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p><fmt:formatDate value="${detail.useDate }"/> </p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">申请时段</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p id="applyLesson"></p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span>使用原因：</span>${detail.useReason }
					</div>
				</div>
				<div class="timeline">
				  	<ul>
				  		<li class="timeline-item"> 
				  			<div class="timeline-item-head-first"> 
				  				<i class="weui_icon weui_icon_success_no_circle timeline-item-checked"></i> 
				  			</div> 
				  			<div class="timeline-item-tail"></div> 
				  			<div class="timeline-item-content"> 
				  				<div class="weui_panel_bd gzsp-timeline-flow">
					                <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">
					                    <div class="weui_media_bd">
					                        <h4 class="weui_media_title">${detail.applyer }</h4>
					                        <p class="weui_media_desc"><span class="f-green">发起申请</span></p>
					                    </div>
					                </a>
								</div>
				  			</div> 
				  		</li>
				  		<c:forEach var="req" items="${detail.reqList }" varStatus="status" begin="${detail.status == '001' ? 0 : 1 }">
					  		<li class="timeline-item"> 
					   			<c:choose>
					   				<c:when test="${req.status == '000'}">
					   					<div class="timeline-item-head-first"> 
							  				<i class="weui_icon weui_icon_success_no_circle timeline-item-checked"></i> 
							  			</div> 
					   				</c:when>
					   				<c:when test="${req.status == '002'}">
					   					<div class=""> 
							   				<img class="gzsp-timeline-flow-img" src="<%=basePath %>/images/bohuishenqing@3x.png">
							   			</div> 
					   				</c:when>
					   				<c:otherwise>
					   					<div class=""> 
							   				<img class="gzsp-timeline-flow-img" src="<%=basePath %>/images/wait_icno.png">
							   			</div> 
					   				</c:otherwise>
					   			</c:choose>
					   			<c:if test="${!status.last }">
					   				<div class="timeline-item-tail" style="top: 25px;"></div> 
					   			</c:if>
					   			<div class="timeline-item-content"> 
					   				<div class="weui_panel_bd gzsp-timeline-flow">
						                <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">
						                    <div class="weui_media_bd">
						                        <h4 class="weui_media_title">
						                        	<c:if test="${req.status != '001'}">${req.teacherName }</c:if>
						                        </h4>
						                        <p class="weui_media_desc">
						                        	<c:choose>
						                        		<c:when test="${req.status == '001'}"><span class="f-yellow2">${req.statusText }</span></c:when>
						                        		<c:when test="${req.status == '000'}"><span class="f-green">${req.statusText }</span></c:when>
		                        						<c:when test="${req.status == '002'}"><span class="f-red">${req.statusText }</span></c:when>
						                        		<c:otherwise>
						                        			<span class="f-yellow2">${req.statusText }</span>
						                        		</c:otherwise>
						                        	</c:choose>
						                        </p>
						                        <c:if test="${req.status == '002'}">
						                        	<p class="">驳回原因：${req.remarks }</p>
						                        </c:if>
						                        <c:if test="${req.status == '004'}">
						                        	<p class="">撤消审批原因：${req.remarks }</p>
						                        </c:if>
						                    </div>
						                </a>
									</div>
					   			</div> 
					   		</li>
				  		</c:forEach>
				     </ul> 
				</div>
			</div>
		</div>
	</div>
	<c:if test="${isEdit }">
		<c:choose>
			<c:when test="${detail.status == '001' && detail.applyerId == user.teacher.id}">
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="cancelSubmit">
			            <span>取消申请</span>
			        </div>
			    </section>
			</c:when>
			<c:when test="${detail.status == '000' && isApprovaler }">
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="rejectSubmit">
			            <span>撤消审批</span>
			            <input type="hidden" id="rejectType" value="1">
			        </div>
			    </section>
			</c:when>
			<c:when test="${detail.status == '001' && isApprovaler}">
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="rejectSubmit">
			            <span>驳回</span>
			            <input type="hidden" id="rejectType" value="2">
			        </div>
			        <div class="weui-menu-inner" id="agreeSubmit">
			            <span>同意</span>
			        </div>
			    </section>
			</c:when>
		</c:choose>
	</c:if>
<!--弹窗-->				
<div class="weui_mask ueureiu weui_mask_visible" style="display: none;z-index:600">
</div>
<!--End弹窗-->
<div class="weui_dialog weui_dialog_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);display:none;z-index:700;">
	<div class="weui_dialog_hd">
		<strong class="weui_dialog_title"></strong>
	</div>
	<div class="weui_dialog_bd">
		<textarea class="weui-prompt-input" style="height: 80px;width: 95%;" rows="10" id="rejectText"></textarea>
	</div>
	<div class="weui_dialog_ft">
		<a href="javascript:;" id="rejectCancel" class="weui_btn_dialog default">取消</a>
		<a href="javascript:;" id="rejectSure" class="weui_btn_dialog primary">确定</a>
	</div>
</div>
<script>
	$(function() {
		$("#applyLesson").html(lessonText("${detail.applyLesson }"));
		$("#cancelSubmit").click(function() {
      		$.confirm("您确定取消申请吗?","", function() {
      			var url = basePath + "/ls/function/room/applyer/cancel";
      			submit(url, {applyId: "${detail.id}"});
            }, function() {
                //取消操作
            });
      	})
      	$("#agreeSubmit").click(function() {
      		$.confirm("您确定审批通过吗?","", function() {
      			var url = basePath + "/ls/function/room/approval/success";
      			submit(url, {applyId: "${detail.id}"});
            }, function() {
                //取消操作
            });
      	})
      	$("#rejectSubmit").click(function() {
   			$(".weui_mask").addClass("weui_mask_visible").show();
   			$(".weui_dialog").addClass("weui_dialog_visible").show();
   			$(".weui_dialog_title").html($("#rejectType").val() == '1' ? "请输入撤消原因" : "请输入驳回原因");
   			$("#rejectCancel").click(function(){
   				$("#rejectText").val(null);
   				$(".weui_mask").hide();
   				$(".weui_dialog").hide();
   			});
   			$("#rejectSure").click(function(){
   				var text = $("#rejectText").val();
   				if(text.trim().length > 0) {
   		      		var params = {
   		      			applyId: "${detail.id}",
   		      			rejectReason: text
   		      		}
   		      		var url = basePath + "/ls/function/room/approval/cancel";
   		      		if($("#rejectType").val() == '2') {
   		      			url = basePath + "/ls/function/room/approval/reject";
   		      		}
   		      		submit(url, params);
    		      	$(".weui_mask").hide();
    				$(".weui_dialog").hide();
    				$("#rejectText").val(null);
   		      	}
   		   });
      	})
	});
	function submit(url, params) {
		$.ajax({
          	url : url,
  	 		type : "post",
  	 		dataType : "json",
  	 		data : params,
            success: function(data){
            	if(data.code == '000') {
            		$.toast("提交成功！");
            		setTimeout(function() {
            			window.location.reload();
            		}, 1000);
            		return;
            	}
            	if(data.code == '1048') {
            		$.alert("与"+data.data.applyer+"教师申请的"+data.data.roomName+"("+lessonText(data.data.applyLesson)+")有冲突","");
            		return;
            	}
            	$.toptips(data.msg);
            },
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
         });
	}
	function lessonText(lesson) {
		var array = [];
		var lessons = lesson.split(',');
		for(var i in lessons) {
			if(parseInt(lessons[i]) == 9) array.push("晚修一");
			else if(parseInt(lessons[i]) == 10) array.push("晚修二");
			else array.push("第" + lessons[i] + "节");
		}
		return array.toString();
	}
</script>
</body>
</html>